package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("category")
public class CategoryController {

    @Reference
    private CategoryService categoryService;

    @RequestMapping("getCategory")
    @ResponseBody
    public Result getCategory(String name) {
        try {
            List<TbContentCategory> categoryList = categoryService.getCategory(name);
            return Result.response(ResultEnum.SUCCESS).setData(categoryList);
        } catch (Exception e) {
            List<TbContentCategory> categoryList = categoryService.getCategory(name);
            return Result.response(ResultEnum.SUCCESS).setData(categoryList);
        }
    }
    @RequestMapping("addInfoCategroy")
    @ResponseBody
    public Result addInfoCategroy(TbContentCategory tbContentCategory){
        int i = categoryService.addInfoCategroy(tbContentCategory);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("deleteInfo")
    @ResponseBody
    public Result deleteInfo(Long[] ids){
        int i = categoryService.deleteInfo(ids);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("toUpdate")
    @ResponseBody
    public Result toUpdate(Long id){
        TbContentCategory category = categoryService.toUpdate(id);
        return Result.response(ResultEnum.SUCCESS).setData(category);
    }
    @RequestMapping("update")
    @ResponseBody
    public Result update(TbContentCategory category){
        int i = categoryService.updateInfo(category);
        return Result.response(ResultEnum.SUCCESS);
    }
}


